<blockquote class="layui-elem-quote">商品类别管理</blockquote>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字</label>
                            <div class="layui-input-inline">
                                <input type="text" id="keyword" name="categoryname" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>


    </div>
</div>
<!--<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>-->
<script >
    layui.use(['form', 'table','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            upload = layui.upload,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/api/user/page',
            toolbar: '#toolbarDemo',
            limits: [5, 10, 15, 20, 100],
            limit: 10,
            page: true,
            skin: 'line',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            request:{
                pageName: 'pageNum',
                limitName: 'pageSize'
            },
            response:{
                statusCode:10000
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            },
            cols: [[
                {field: 'id',  title: 'ID', sort: true},
                {field: 'username', title: '用户名', sort: true},
                {field: 'phone', title: '手机', sort: true},
                {field: 'email', title: '邮箱', sort: true},
                {field: 'realname', title: '真实姓名', sort: true},
                {field: 'gender', title: '性别', sort: true},
                {field: 'idcard', title: '身份证', sort: true},
                {field: 'money', title: '金额', sort: true},
                {field: 'status', title: '是否禁用', templet:function (d) {
                        return ['正常','禁用'][d.status]
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
        });

        //监听搜索按钮时间
        $("#keyword").on("input",function (){
            let name = $(this).val();
            table.reload("currentTableId", {
                page: {
                    curr:1
                },
                where:{
                    username: name,
                    realname: name,
                }
            })
        })


        /**
         * toolbar监听事件
         */

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                sessionStorage.setItem("id",data.id);
                layer.open({
                    type:2,
                    title:"修改分类信息",
                    area:['800px','500px'],
                    content:'/user/userUpdate.html',
                    end: function () {
                        table.reload("currentTableId")
                    }
                })


            }
        });

    });
</script>
